package com.example.sjm.activity_bysjm;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

public class ListViewAdapter extends BaseAdapter {
    Context context;
    List<ListViewModel> listViewModels;

    public ListViewAdapter(Context context, List<ListViewModel> listViewModels) {
        this.context = context;
        this.listViewModels = listViewModels;
    }

    @Override
    public int getCount() {
        return listViewModels.size();
    }

    @Override
    public Object getItem(int i) {
        return listViewModels.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        View myView=View.inflate(context,R.layout.item,null);
        TextView textView=myView.findViewById(R.id.name);
        //TextView textView2=myView.findViewById(R.id.activity_id);
        System.out.println("bmob"+2);
        ImageView imageView=myView.findViewById(R.id.img);
        textView.setText(listViewModels.get(i).getName());
        Glide.with(context).load(listViewModels.get(i).getImgUrl()).into(imageView);
        return myView;
    }
}
